(function($) {//format form query string to object
$.fn.serializeFormJSON = function() {

   var o = {};
   var a = this.serializeArray();
   $.each(a, function() {
       if (o[this.name]) {
           if (!o[this.name].push) {
               o[this.name] = [o[this.name]];
           }
           o[this.name].push(this.value || '');
       } else {
           o[this.name] = this.value || '';
       }
   });
   return o;
};
})(jQuery);

$(function(){

    //全局的ajax访问，处理ajax清求时sesion超时  
    $.ajaxSetup({   
        contentType:"application/x-www-form-urlencoded;charset=utf-8",   
        complete:function(XMLHttpRequest,textStatus){   
            if(XMLHttpRequest.status == 403) {
                window.parent.openLogin();
                return false;
            }
        }
    }); 
    $('.tip').live('click',function(){
        //var src = $(this).attr('src');
        //var img = '<img src="'+src+'" width="250"/>';
        
        });
    $('.removeImg').live('click', function(){
        $(this).parent().remove();
    });

});

/**
 * id 数据库字段
 * path 配置文件里面的上传配置路径
 * 文件上传处理的Action
 *
 */
function uploadBase(id,path,url){
    $('#'+id+'_upload').uploadify({
        'formData'     : {
            'ajax' : '1'
        },
        height: 24,
        width  : 110,

        buttonText : '选择文件',
        fileTypeDesc : 'Image Files',
        fileTypeExts : '*.gif; *.jpg; *.png; *.jpeg', 
        swf      : TP_JS+'/upload/uploadify.swf',
        uploader : TP_APP+'/Upload/'+url,

        onUploadSuccess : function(file, data, response) {
            var data = eval('('+data+')');
            //alert(data.info);
            if(data.data) {
                $('#'+file.id).addClass('uploadify-success');
                var imgUrl = SITE_URL+'/'+path+data.info;
                var img = '<img class="tip" src="'+imgUrl+'" />';
                $('.'+id+'_show').html(img);
                $('#'+id).val(imgUrl);
            }else{
                $('#'+file.id).addClass('uploadify-error');
                    
            }
        } 
    });
}

function uploadOss(id,path,url){
    $('#'+id+'_upload').uploadify({
        'formData'     : {
            'ajax' : '1'
        },
        height: 24,
        width  : 110,
        buttonText : '选择文件',
        fileTypeDesc : 'Image Files',
        fileTypeExts : '*.gif; *.jpg; *.png; *.jpeg', 
        swf      : TP_JS+'/upload/uploadify.swf',
        uploader : TP_APP+'/Upload/'+url,
        
        onUploadSuccess : function(file, data, response) {
            var data = eval('('+data+')');
            //alert(data.info);
            if(data.data) {
                $('#'+file.id).addClass('uploadify-success');
                var html = '<div class="img-input"><img title="'+data.info+'" class="tip" src="'+data.info+'"  width="80" />';
                html += '排序<input type="text" name="sort[]" value="0"/> <span class="removeImg">移除</span></div>';
                $('.'+id+'_show').prepend(html);

            }else{
                $('#'+file.id).addClass('uploadify-error');
                    
            }
        } 
    });
}

function addLoading(){
    $('.submit-icon').parent().append('<div class="loading"></div>');
}
function removeLoading(){
    $('.loading').remove();
}
function ShowObjProperty(Obj) 
{ 
    var PropertyList=''; 
    var PropertyCount=0; 
    for(i in Obj){ 
        if(Obj.i !=null) 
            PropertyList=PropertyList+i+'属性：'+Obj.i+'\r\n'; 
        else 
            PropertyList=PropertyList+i+'方法\r\n'; 
    } 
    alert(PropertyList); 
} 

function submitThisForm(){
    $('#ajaxForm').form('submit', {  
        url: url,
        onSubmit:function(){    
            editor.sync('content');
            return $(this).form('validate');    
        },    
        success:function(data){  
            var obj = eval("("+data+")");
            var icon = 'info';
            if(obj.status == 0) {
                icon = 'error';
            }
            if(obj.status == -1) {
                icon = 'warning';
            }
            if(obj.status == 1 ) {
                    
                $('#w').window('close');
                $("#items").datagrid('reload');
            }
            //$('#tabs', 'window.parent.document').tabs('getSelected').update();
            //$.messager.alert('操作提示', obj.info, icon);  

            $.messager.show({   // show error message  
                title: '提示信息',  
                msg: obj.info  
            });
        }    
    });
}

function cleanImage(){
    $('.pic_url_show img').each(function(){
        var src = $(this).attr('src');
        var image=new Image();
        image.src = src;
        var width = image .width;
        var height= image .height;
        if(width < 220 || height < 70) {
            $(this).parent().remove();
        }
    });
}
function submitImageForm(){
    
    $('.up_images').remove();
    $('.pic_url_show img').each(function(){
        var src = $(this).attr('src');
        var html = '<input type="hidden" class="up_images" name="uploadImage[]" value="'+src+'"/>';
        $(this).parent().append(html);
    });
    var fromIdBase = 'ajaxForm';
    if(formId != '') {
        fromIdBase = formId;
    }

    $('#'+fromIdBase).form('submit', {  
        url: url,
        onSubmit:function(){    
            if($(this).form('validate')){
                addLoading();
                setTimeout(function(){$('#x').window('close');}, 2000);
            } else {
                return false;
            }

        },    
        success:function(data){  
            var obj = eval("("+data+")");
            var icon = 'info';
            obj.info = '数据已经提交';
            if(obj.status == 0) {
                icon = 'error';
                obj.info = '操作失败';
            }
            if(obj.status == -1) {
                icon = 'warning';
                obj.info = '操作失败';
            }
            if(obj.status == 1 || obj.status == 200) {
                    
                $('#x').window('close');
                $("#items").datagrid('reload');
               _after_success();
                // if(obj.info == '' || obj.info == null) {
                obj.info = '操作成功';
                // }
            }
            
            //$('#tabs', 'window.parent.document').tabs('getSelected').update();
            //$.messager.alert('操作提示', obj.info, icon);  

            $.messager.show({   // show error message  
                title: '提示信息',  
                msg: obj.info  
            });
            removeLoading();

        }    
    });
}
function submitImageEditForm(){
    
    $('.edit_up_images').remove();
    $('.edit_pic_url_show img').each(function(){
        var src = $(this).attr('title');
        var html = '<input type="hidden" class="edit_up_images" name="uploadImage[]" value="'+src+'"/>';
        $(this).parent().append(html);
    });
    var fromIdBase = 'ajaxForm';
    if(formId != '') {
        fromIdBase = formId;
    }

    $('#'+fromIdBase).form('submit', {  
        url: url,
        onSubmit:function(){    
            if($(this).form('validate')){
                addLoading();
                setTimeout(function(){$('#y').window('close');}, 2000);
            } else {
                return false;
            }
        },    
        success:function(data){  
            var obj = eval("("+data+")");
            var icon = 'info';
            obj.info = '数据已经提交';
            if(obj.status == 0) {
                icon = 'error';
                obj.info = '操作失败';
            }
            if(obj.status == -1) {
                icon = 'warning';
                obj.info = '操作失败';
            }
            if(obj.status == 1 || obj.status == 200) {
                    
                $('#w').window('close');
                $("#items").datagrid('reload');
                _after_success();
                if(obj.info == '' || obj.info == null) {
                    obj.info = '操作成功';
                }
            }
            
            //$('#tabs', 'window.parent.document').tabs('getSelected').update();
            //$.messager.alert('操作提示', obj.info, icon);  

            $.messager.show({   // show error message  
                title: '提示信息',  
                msg: obj.info  
            });
            removeLoading();
        }    
    });
}



function submitBaseForm(){
     
    var fromIdBase = 'ajaxForm';
    if(formId != '') {
        fromIdBase = formId;
    }

    $('#'+fromIdBase).form('submit', {  
        url: url,
        onSubmit:function(){    
             if($(this).form('validate')){
                 addLoading();
             }    else {
                 return false;
             }
        },    
        success:function(data){  
            var obj = eval("("+data+")");
            var icon = 'info';
            if(obj.status == 0) {
                icon = 'error';
            }
            if(obj.status == -1) {
                icon = 'warning';
            }
            if(obj.status == 1 || obj.status == 200) {
                    
                $('#w').window('close');
                $("#items").datagrid('reload');
                _after_success();
                if(obj.info == '' || obj.info == null) {
                    obj.info = '操作成功';
                }
            }

            $.messager.show({   // show error message  
                title: '提示信息',  
                msg: obj.info  
            });
            removeLoading();

        }    
    });
}

function submitTreeForm(){

    $('#treeForm').form('submit', {  
        url: url,
        onSubmit:function(){
            if($(this).form('validate')){
                 addLoading();
             }    else {
                 return false;
             }
        },    
        success:function(data){  
            var obj = eval("("+data+")");
            var icon = 'info';
            if(obj.status == 0) {
                icon = 'error';
            }
            if(obj.status == -1) {
                icon = 'warning';
            }
            if(obj.status == 1 ) {  
                $('#t').window('close');
                $('#category_search').combotree('reload');
                $('#parent_tree').combotree('reload');
                $('#article_cat').combotree('reload');
                $('#tree').tree('reload'); 
            }
            //$('#tabs', 'window.parent.document').tabs('getSelected').update();
            $.messager.show({   // show error message  
                title: '提示信息',  
                msg: obj.info  
            });  
            removeLoading();
        //$.messager.alert('操作提示', obj.info, icon);    
        }    
    });
}

function updateTree(){
    $('#items').treegrid('reload');
}
function updateGrid(){
    $('#items').datagrid('reload');
}
function deleteData(gridId, url, name){
    var rows = $('#'+gridId).datagrid('getSelections');  
    var length = rows.length;
    if (length > 0){  
        $.messager.confirm('Confirm','你确定删除吗？',function(r){  
            if (r){
                var deleteIds = [];
                for(var i = 0; i < length; i++) {
                    deleteIds.push(rows[i][name]);
                }
                $.post(url,{
                    ids:deleteIds,
                    'ajax':1
                },function(result){  
                    //var rs = eval("("+result+")");
                    if (result.status == 1){  
                        $('#'+gridId).datagrid('reload');    // reload the user data  
                        $.messager.show({   // show error message  
                            title: '恭喜您：',  
                            msg: result.info  
                        });  
                    } else {  
                        
                        $.messager.show({   // show error message  
                            title: '错误提示',  
                            msg: result.info  
                        });  
                    }  
                },'json');  
            }  
        });  
    } else {
        $.messager.show({   // show error message  
            title: '错误提示',  
            msg: '请选择要删除的记录'  
        }); 
    }  
}  

function setData (gridId, url, name, act){
    var rows = $('#'+gridId).datagrid('getSelections');  
    var length = rows.length;
    if (length > 0){  
        $.messager.confirm('Confirm','你确定进行这个操作吗？',function(r){  
            if (r){
                var deleteIds = [];
                for(var i = 0; i < length; i++) {
                    deleteIds.push(rows[i][name]);
                }
                $.post(url,{
                    'ids':deleteIds,
                    'act':act,
                    'ajax':1
                },function(result){  
                    //var rs = eval("("+result+")");
                    if (result.status == 1){  
                        $('#'+gridId).datagrid('reload');    // reload the user data  
                        $.messager.show({   // show error message  
                            title: '恭喜您：',  
                            msg: result.info  
                        });  
                    } else if(result.status == 0) {  
                        
                        $.messager.show({   // show error message  
                            title: '错误提示',  
                            msg: result.info  
                        });  
                    } else{
                        $('#'+gridId).datagrid('reload');    // reload the user data  
                        $.messager.show({   // show error message  
                            title: '恭喜您：',  
                            msg: '操作成功'  
                        });  
                    }
                },'json');  
            }  
        });  
    } else {
        $.messager.show({   // show error message  
            title: '错误提示',  
            msg: '请选择'  
        }); 
    }  
}  

function setTreeData (gridId, url, name, act){
    var rows = $('#'+gridId).treegrid('getSelections');  
    var length = rows.length;
    if (length > 0){  
        $.messager.confirm('Confirm','你确定进行这个操作吗？',function(r){  
            if (r){
                var deleteIds = [];
                for(var i = 0; i < length; i++) {
                    deleteIds.push(rows[i][name]);
                }
                $.post(url,{
                    'ids':deleteIds,
                    'act':act,
                    'ajax':1
                },function(result){  
                    //var rs = eval("("+result+")");
                    if (result.status == 1){  

                        $('#'+gridId).treegrid('reload');    // reload the user data  
                        $.messager.show({   // show error message  
                            title: '恭喜您：',  
                            msg: result.info  
                        });  
                    } else if(result.status == 0) {  
                        
                        $.messager.show({   // show error message  
                            title: '错误提示',  
                            msg: result.info  
                        });  
                    } else{
                        $('#'+gridId).datagrid('reload');    // reload the user data  
                        $.messager.show({   // show error message  
                            title: '恭喜您：',  
                            msg: '操作成功'  
                        });  
                    }
                },'json');  
            }  
        });  
    } else {
        $.messager.show({   // show error message  
            title: '错误提示',  
            msg: '请选择'  
        }); 
    }  
}  

function getSelected(){  
    var node = $('#tree').tree('getSelected');  
    if (node){  
        var s = node.text;  
        if (node.attributes){  
            s += ","+node.attributes.p1+","+node.attributes.p2;  
        }  
        alert(s);  
    }  
} 

function treeReload(id) {
    var node = $('#'+id).tree('reload'); 
}
//格式化日期
Date.prototype.format = function(format) {
    var returnStr = '';
    var replace = Date.replaceChars;
    for (var i = 0; i < format.length; i++) {
        var curChar = format.charAt(i);
        if (replace[curChar]) {
            returnStr += replace[curChar].call(this);
        } else {
            returnStr += curChar;
        }
    }
    return returnStr;
};
Date.replaceChars = {
    shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
 
    // Day
    d: function() {
        return (this.getDate() < 10 ? '0' : '') + this.getDate();
    },
    D: function() {
        return Date.replaceChars.shortDays[this.getDay()];
    },
    j: function() {
        return this.getDate();
    },
    l: function() {
        return Date.replaceChars.longDays[this.getDay()];
    },
    N: function() {
        return this.getDay() + 1;
    },
    S: function() {
        return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th')));
    },
    w: function() {
        return this.getDay();
    },
    z: function() {
        return "Not Yet Supported";
    },
    // Week
    W: function() {
        return "Not Yet Supported";
    },
    // Month
    F: function() {
        return Date.replaceChars.longMonths[this.getMonth()];
    },
    m: function() {
        return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1);
    },
    M: function() {
        return Date.replaceChars.shortMonths[this.getMonth()];
    },
    n: function() {
        return this.getMonth() + 1;
    },
    t: function() {
        return "Not Yet Supported";
    },
    // Year
    L: function() {
        return (((this.getFullYear()%4==0)&&(this.getFullYear()%100 != 0)) || (this.getFullYear()%400==0)) ? '1' : '0';
    },
    o: function() {
        return "Not Supported";
    },
    Y: function() {
        return this.getFullYear();
    },
    y: function() {
        return ('' + this.getFullYear()).substr(2);
    },
    // Time
    a: function() {
        return this.getHours() < 12 ? 'am' : 'pm';
    },
    A: function() {
        return this.getHours() < 12 ? 'AM' : 'PM';
    },
    B: function() {
        return "Not Yet Supported";
    },
    g: function() {
        return this.getHours() % 12 || 12;
    },
    G: function() {
        return this.getHours();
    },
    h: function() {
        return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12);
    },
    H: function() {
        return (this.getHours() < 10 ? '0' : '') + this.getHours();
    },
    i: function() {
        return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes();
    },
    s: function() {
        return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
    },
    // Timezone
    e: function() {
        return "Not Yet Supported";
    },
    I: function() {
        return "Not Supported";
    },
    O: function() {
        return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00';
    },
    P: function() {
        return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':' + (Math.abs(this.getTimezoneOffset() % 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() % 60));
    },
    T: function() {
        var m = this.getMonth();
        this.setMonth(0);
        var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1');
        this.setMonth(m);
        return result;
    },
    Z: function() {
        return -this.getTimezoneOffset() * 60;
    },
    // Full Date/Time
    c: function() {
        return this.format("Y-m-d") + "T" + this.format("H:i:sP");
    },
    r: function() {
        return this.toString();
    },
    U: function() {
        return this.getTime() / 1000;
    }
};

function formatMoney(number, places, thousand, decimal) {
    if(number == null){
        return 0;
    }
    number = number.toString();
    number =number.substr(0,number.length-2)+'.'+ number.substr(number.length-2,number.length);
    number = number || 0;
    places = !isNaN(places = Math.abs(places)) ? places : 2;
    thousand = thousand || ",";
    decimal = decimal || ".";
    var negative = number < 0 ? "-" : "",
    i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
    j = (j = i.length) > 3 ? j % 3 : 0;
    return '￥'+negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}

function clearContent(str) {
    str = str.substring(0,4);//截取字符个数
    return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}

function showStatus(value) {
    switch(value) {
        case '1' :
            return '开启';
            break;
        case '0' :
            return'关闭';
            break;
        case 1 :
            return '开启';
            break;
        case 0 :
            return'关闭';
            break;
    }
}

function showAdsStatus(value) {
    switch(value) {
        case '1' :
            return '开启';
            break;
        case '0' :
            return'关闭';
            break;
    }

}

function showPromotion(value) {
    switch(value) {
        case '10' :
            return '商城';
            break;
        case '20' :
            return'橱窗';
            break;
        case '30' :
            return'精品';
            break;
        default:
            return '其他';
            break;
    }

}


function showAdsType(value) {
    switch(value) {
        case '1' :
            return '商品类型';
            break;
        case '2' :
            return '图片类型';
            break;
    }

}
function showAppStatus(value){
    switch(value) {
        case '0' :
            return '<span class="red">无效(禁止)</span>';
            break;
        case '1' :
            return '<span class="green">有效</span>';
            break;
        case '2' :
            return '<span class="green">运行中</span>';
            break;
        case '4' :
            return '<span class="red">删除状态</span>';
            break;
    }

}

function getDevType(type) {
    if(type == '1'){
        return '<span class="green">个人</span>';
    }
    else if(type == '2') {
        return '<span class="green">公司</span>';
    }
    else  {
        return '<span class="red">待定</span>';
    }
}

function getDevStatus(type) {
    if(type == '1'){
        return '<span class="green">已经激活</span>';
    }
    else if(type == '0') {
        return '<span class="red">等待激活</span>';
    }

}

function showPlat(type) {
    if(type == '1'){
        return 'IOS';
    }
    if(type == '2') {
        return 'Android';
    }
    if(type == -1) {
        return 'Windows Mobile';
    }
}

function getCertificateType(type) {
    if(type == '1'){
        return '中国大陆身份证';
    }
    if(type == '2') {
        return '港澳台身份证';
    }
    if(type == '3') {
        return '其它证件';
    }
    if(type == null) {
        return '公司营业执照';
    }
}
function showSex(value){
    switch(value) {
        case '0' :
            return '男';
            break;
        case '1' :
            return'女';
            break;
        case '2' :
            return'未知';
            break;
    }
}

function showMemberStatus(value){
    switch(value) {
        case 0 :
            return '正常';
            break;
        case 1 :
            return'禁言';
            break;
    }
}

function showFl(value){
    return '已返利';
}
function showSnsFrom(value){
    switch(value) {
        case 'SINA' :
            return 'SINA';
            break;
        case 'QQ' :
            return'QQ';
            break;
        case 'Taobao' :
            return'Taobao';
            break;
        case '' :
            return'未知';
            break;
    }
}

function showCommentsStatus(value){
    switch(value) {
        case 0 :
            return '初始';
            break;
        case 1 :
            return '未通过';
            break;
        case 2 :
            return '通过';
            break;
    }    
}
//日期格式化
function getFormatTime(timestamp) {  
    if(timestamp == '' || timestamp == null) {
        return '空';
    }
    timestamp = timestamp.toString();
    if(timestamp.length != 13) {
        timestamp = parseInt(timestamp)*1000;
    }
    var date = (new Date(parseInt(timestamp)));
    return date.format('Y-m-d H:i:s');
}  


function showImg(img) {
    if(img == '' || img == null || img == 'undefined') {
        return '<img src="'+TP_IMAGES+'/appgo.png" height="60"/>';
    }
    return '<img src="'+img+'" height="60"/>';
}
function showTaobaoImg(img) {
    if(img == '' || img == null || img == 'undefined') {
        return '<img src="'+TP_IMAGES+'/appgo.png" height="60"/>';
    }
    return '<img src="'+img+'_60x60.jpg" height="60"/>'
}
function showImgDecode(img) {
    if(img == '' || img == null || img == 'undefined') {
        return '<img src="'+TP_IMAGES+'/default.png" height="60"/>';
    }
    return '<img src="'+unescape(img)+'" height="60"/>'
}

/********************************/
//搜索订单
function searchOrderData() {
    var keyword = $('#keyword').val();
    $("#itemsTaobao").datagrid('load',{
        'keyword': keyword
    }); 
}
//重置订单
function resetOrderData() {
    $('#searchForm').form('clear'); 
    $("#itemsTaobao").datagrid('load',{
        'keyword' : ''
    }); 
}

function loadTaobaoOrder(appid, developer_id){
    $('#itemsTaobao').datagrid({
        url : TP_APP+'/Admin/TaobaoOrder/jsonData',
        title : '淘宝订单',
        pagination : true,
        pagePosition : 'both',
        pageSize : 20,
        fit : true,
        fitColumns : true,
        idField : 'tborder_id',
        queryParams : {
            'developer_id' : developer_id, 
            'appid' : appid
        },
        columns:[[
        {
            align:'right',
            field:'tborder_id',
            title:'订单',
            width:60,
            checkbox:true
        },
        {
            align:'left',
            field:'trade_id',
            title:'订单号',
            width:140
        },
        {
            align:'center',
            field:'created',
            title:'购买时间',
            width:140
        },
        {
            align:'left',
            field:'buyer_nick',
            title:'购买用户',
            width:100
        },
        {
            align:'left',
            field:'promotion',
            title:'推广渠道',
            width:100,
            formatter : showPromotion
        },
        {
            align:'left',
            field:'realname',
            title:'开发者',
            width:100
        },
        {
            align:'left',
            field:'name',
            title:'所属应用',
            width:100
        },
        {
            align:'center',
            field:'pic_url',
            title:'商品图片',
            width:80,
            formatter : showTaobaoImg
        },
        
        {
            align:'center',
            field:'title',
            title:'商品',
            width:240
        },

        {
            align:'center',
            field:'num',
            title:'数量',
            width:70
        },


        {
            align:'center',
            field:'price',
            title:'单价',
            width:70, 
            formatter : formatMoney
        },

        {
            align:'center',
            field:'commission',
            title:'佣金 （数量*佣金）',
            width:120, 
            formatter : formatMoney
        },

        {
            align:'center',
            field:'payment',
            title:'总价',
            width:100, 
            formatter : formatMoney
        },
        {
            align:'center',
            field:'status',
            title:'是否返利',
            width:100, 
            formatter : showFl
        }
        ]],
    toolbar:[{
                    id:'order_shop',
                    text:'商城订单',
                    iconCls:'icon-search',
                    handler:function(){
                        $('#promotion').val(10);
                        searchGrid('searchForm','itemsTaobao');
                    }
                },'-',
                {
                    id:'order_showcase',
                    text:'橱窗订单',
                    iconCls:'icon-search',
                    handler:function(){
                        $('#promotion').val(20);
                        searchGrid('searchForm','itemsTaobao');
                    }
                },'-',
                {
                    id:'order_showcase',
                    text:'精品订单',
                    iconCls:'icon-search',
                    handler:function(){
                        $('#promotion').val(30);
                        searchGrid('searchForm','itemsTaobao');
                    }
                }
    ]
    });
}
//searchGrid
function searchGrid(formid,grid){
    var formObj = $('#'+formid).serializeFormJSON();
    $("#"+grid).datagrid('load',formObj);
}

function resetGrid(formid,grid){
    $('#'+formid).form('clear'); 
    var formObj = $('#'+formid).serializeFormJSON();
    $("#"+grid).datagrid('load',formObj);
}


function loadAppReport(appkey, developer_id){
    $('#itemsReport').datagrid({
        url : TP_APP+'/Admin/AppReport/jsonData',
        title : '报表数据',
        pagination : true,
        pagePosition : 'both',
        pageSize : 20,
        fit : true,
        fitColumns : true,
        idField : 'app_detail_id',
        queryParams : {
            'developer_id' : developer_id, 
            'appkey' : appkey
        },
        columns:[[
        {
            align:'right',
            field:'app_detail_id',
            title:'报表数据',
            width:60,
            checkbox:true
        },

        {
            align:'left',
            field:'realname',
            title:'开发者',
            width:100
        },

        {
            align:'left',
            field:'name',
            title:'对应App',
            width:100
        },

        {
            align:'left',
            field:'appkey',
            title:'appkey',
            width:240
        },

        {
            align:'center',
            field:'detail_date',
            title:'报表日期',
            width:100
        },

        {
            align:'left',
            field:'trading_volume',
            title:'成交量',
            width:100,
            formatter :  showEmpty
        },

        {
            align:'left',
            field:'item_pv',
            title:'浏览量',
            width:100,
            formatter :  showEmpty
        },

        {
            align:'left',
            field:'profit',
            title:'收益',
            width:100, 
            formatter : formatMoney
        },

        {
            align:'left',
            field:'intent_buy_volume',
            title:'购买意向',
            width:100,
            formatter :  showEmpty
        },

        {
            align:'left',
            field:'promotion',
            title:'报表类型',
            width:100,
            formatter :  showPromotion
        }
        ]],
        onDblClickRow : function(rowIndex, row){
            var id = row.app_detail_id;
            $.post(TP_APP+'/Admin/AppReport/getOne',{
                id:id
            }, function(data){
                $('#ajaxForm').form('load',data);
            },'json');
            $('#w').window('open').window('setTitle','编辑数据');
            url = '__URL__/update';
        }

    });
}

function showZero(value){
    if(value == '' || value == null){
        return 0;
    }
    return value;
}
function showEmpty(value){
    if(value == '' || value == null){
        return '<i style="color:#ccc">暂无数据</i>';
    }
    return value;
}


/************************/